//
//  SNFoodMealEditTableViewCell.m
//  project
//
//  Created by 黄建华 on 2018/11/14.
//  Copyright © 2018年 黄建华. All rights reserved.
//

#import "SNFoodMealEditTableViewCell.h"

@implementation SNFoodMealEditTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    
    return self;
}

- (void)createView {
    _view = [[UIView alloc] init];
    [self addSubview:_view];
    
    _numLabel = [[UILabel alloc] init];
    [self addSubview:_numLabel];
    
    _shadowV1 = [[SNShadowView alloc] init];
    [self addSubview:_shadowV1];
    
    _shadowV2 = [[SNShadowView alloc] init];
    [self addSubview:_shadowV2];
    
    _shadowV3 = [[SNShadowView alloc] init];
    [self addSubview:_shadowV3];
    
    _shadowV4 = [[SNShadowView alloc] init];
    [self addSubview:_shadowV4];
    
    _jjSearchView = [[JJSearchOptionView alloc] init];
    [_shadowV1 addSubview:_jjSearchView];
    
    _weightTx = [[UITextField alloc] init];
    [_shadowV2 addSubview:_weightTx];
    
    _unitJJSearchView = [[JJOptionView alloc] init];
    [_shadowV3 addSubview:_unitJJSearchView];
    
    _calorTx = [[UITextField alloc] init];
    [_shadowV4 addSubview:_calorTx];
}

- (void)updateCellWithModel:(NSDictionary *)dic {
//    NSLog(@"tag >>>>>%d", self.tag);
    CGFloat width = HHHWIDTH - 20;
    
    _view.frame = SNFRAME(0, 0, width, 40);
    
    _numLabel.textAlignment = NSTextAlignmentCenter;
    _numLabel.font          = SNFONT(SNFITFONTSIZE(15));
    _numLabel.text = StrByInt(self.tag +1);
    _numLabel.frame         = SNFRAME(0, 10, 30, 20);
    _numLabel.textColor     = FOODCOLOR;
    
    _shadowV1.frame              = SNFRAME(_numLabel.right, 5, width/2 -_numLabel.right, 30);
    _shadowV1.layer.borderWidth  = 0.5;
    _shadowV1.layer.borderColor  = SNCOLORGRAYLINE.CGColor;
    _shadowV1.layer.cornerRadius = 5.0;
    
    _jjSearchView.frame = SNFRAME(0, 0, _shadowV1.width, 30);
    [_jjSearchView setUI];
    _jjSearchView.dataSource = [NSMutableArray array];
    NSString *name = dic[@"name"];
    _jjSearchView.foodNames  = name.length >0 ?name:SN_Text(@"");
    _jjSearchView.tag        = self.tag;
    
    _shadowV2.frame              = SNFRAME(width/2 +5, 5, width/6 - 10, 30);
    _shadowV2.layer.borderWidth  = 0.5;
    _shadowV2.layer.borderColor  = SNCOLORGRAYLINE.CGColor;
    _shadowV2.layer.cornerRadius = 5.0;
    
    _weightTx.frame         = SNFRAME(0, 0, _shadowV2.width, 30);
     NSString *weight = dic[@"amount"];
    _weightTx.text          = weight.length > 0?weight:SN_Text(@"");
    _weightTx.font          = SNFONT(SNFITFONTSIZE(14));
    _weightTx.tag           = self.tag +100;
    _weightTx.textAlignment = NSTextAlignmentCenter;
    _weightTx.keyboardType  = UIKeyboardTypeDecimalPad;
    
    _shadowV3.frame              = SNFRAME(width/2 +5 + width/6, 5, width/6 - 10, 30);
    _shadowV3.layer.borderWidth  = 0.5;
    _shadowV3.layer.borderColor  = SNCOLORGRAYLINE.CGColor;
    _shadowV3.layer.cornerRadius = 5.0;
    
    _unitJJSearchView.frame = SNFRAME(0, 0, _shadowV3.width, 30);
    [_unitJJSearchView setUI];
    _unitJJSearchView.dataSource = SN_FoodClass.foodUnitArray;
    NSString *unit = dic[@"unit"];
    _unitJJSearchView.title      = unit.length > 0?unit:@"";
    _unitJJSearchView.tag        = self.tag;
    
    _shadowV4.frame              = SNFRAME(width/2 +5+ width/6 *2, 5, width/6 - 10, 30);
    _shadowV4.layer.borderWidth  = 0.5;
    _shadowV4.layer.borderColor  = SNCOLORGRAYLINE.CGColor;
    _shadowV4.layer.cornerRadius = 5.0;
    
    _calorTx.frame         = SNFRAME(0, 0, _shadowV4.width, 30);
    NSString *calorS = dic[@"calory"];
    NSString *calor = [NSString stringWithFormat:@"%d",calorS.intValue];
    if (calor.intValue == 0) {
        calor = @"";
    }
    _calorTx.text = calor.length > 0?calor:@"";
    _calorTx.font          = SNFONT(SNFITFONTSIZE(14));
    _calorTx.keyboardType  = UIKeyboardTypeNumberPad;
    _calorTx.textAlignment = NSTextAlignmentCenter;
    _calorTx.tag           = self.tag+200;
}

@end
